package com.segway.robot.host.coreservice.vision.sample;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

import com.segway.robot.host.coreservice.vision.sample.R;
import com.segway.robot.sdk.base.bind.ServiceBinder;
import com.segway.robot.sdk.locomotion.sbv.Base;

import java.util.TimerTask;

public class ShowPhotoActivity  extends Activity{

    private ImageView imageView;

    Base mBase;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.show_photo);

        imageView = (ImageView) findViewById(R.id.image);

        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                Bitmap bitmap = BitmapUtil.getBitMap();

                Log.v("test", "" + bitmap.getHeight() + " " + bitmap.getWidth());
                imageView.setImageBitmap(bitmap);
            }
        };

        runOnUiThread(runnable);

        mBase = Base.getInstance();


        mBase.bindService(getApplicationContext(), new ServiceBinder.BindStateListener() {
            @Override
            public void onBind() {

                mBase.setControlMode(Base.CONTROL_MODE_RAW);

                TimerTask task = new TimerTask() {
                    public void run() {

                        mBase.setLinearVelocity(0.6f);

                        try {
                            Thread.sleep(3000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }

                        mBase.setLinearVelocity(0);
                    }
                };

                java.util.Timer timer = new java.util.Timer(true);

                timer.schedule(task, 1000);
            }

            @Override
            public void onUnbind(String reason) {
            }
        });

    }
}
